package com.vision.core.sv.db.mgr;

import java.util.Collection;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Projection;
import org.hibernate.criterion.ProjectionList;
import org.hibernate.transform.ResultTransformer;

/**
 * Simple Facade interface that provides short-named convenience methods to define
 * a {@link DetachedCriteria}.
 * 
 * @author Mark
 *
 */
public interface ISimpleCriteria {
	
	DetachedCriteria getDetached();
	
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	
	Criterion add(Criterion c);
	
	Criterion notNull(String property);
	
	Criterion isNull(String property);
	
	Criterion or(Criterion c1, Criterion c2);
	
	Criterion eq(String property, Object value);
	
	Criterion in(String property, Collection<?> values);
	
	Criterion in(String property, Object... values);
	
	Criterion neq(String property, Object value);
	
	Criterion lt(String property, Object value);
	
	Criterion leq(String property, Object value);
	
	Criterion gt(String property, Object value);
	
	Criterion geq(String property, Object value);
	
	Criterion between(String property, Object v1, Object v2);
	
	Criterion inBetween(String property, Object v1, Object v2);
	
	Criterion like(String property, String value);
	
	Criterion like(String property, String value, MatchMode matchMode);
	
	Criterion ilike(String property, String value);
	
	Criterion ilike(String property, String value, MatchMode matchMode);
	
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	
	Projection count();
	
	void asc(String... properties);
	
	void desc(String... properties);
	
	/**
	 * Groups the returned data using the column names matching the specified
	 * <tt>properties</tt> list. 
	 * 
	 * @param properties
	 * @return
	 */
	ProjectionList group(String... properties);
	
	/**
	 * Filters the columns that will be included in the returned object. This is
	 * useful when your DTO/table has many fields/columns and you wish to retrieve
	 * only a few fields/columns.
	 * 
	 *  Ex: instead of:
	 *  <pre>
	 *  	SELECT * FROM my_table
	 *  </pre>
	 *  you can do:
	 *  <pre>
	 *  	SELECT col_a, col_b, col_c FROM my_table
	 *  </pre>
	 * 
	 * @param properties
	 * @return
	 */
	ProjectionList properties(String... properties);
	
	void setResultTransformer(ResultTransformer transformer);

}
